package com.ruoyi.security.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.security.domain.AfSafetyInspection;
import com.ruoyi.security.service.IAfSafetyInspectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 安全检查Controller
 *
 * @author cjie
 * @date 2021-12-08
 */
@Api(tags = " 安全检查")
@RestController
@RequestMapping("/afSafetyInspection")
public class AfSafetyInspectionController extends BaseController {
    @Autowired
    private IAfSafetyInspectionService afSafetyInspectionService;

    /**
     * 查询安全检查列表
     */
    @ApiOperation(value="查询安全检查列表", notes="查询安全检查列表")
    @PreAuthorize(hasPermi = "security:afSafetyInspection:list")
    @GetMapping("/list")
    public TableDataInfo list(AfSafetyInspection afSafetyInspection) {
        startPage();
        List<AfSafetyInspection> list = afSafetyInspectionService.selectAfSafetyInspectionList(afSafetyInspection);
        return getDataTable(list);
    }

    /**
     * 导出安全检查列表
     */
    @ApiOperation(value="导出安全检查列表", notes="导出安全检查列表")
    @PreAuthorize(hasPermi = "security:afSafetyInspection:export")
    @Log(title = "安全检查", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AfSafetyInspection afSafetyInspection) throws IOException {
        List<AfSafetyInspection> list = afSafetyInspectionService.selectAfSafetyInspectionList(afSafetyInspection);
        ExcelUtil<AfSafetyInspection> util = new ExcelUtil<AfSafetyInspection>(AfSafetyInspection.class);
        util.exportExcel(response, list, "安全检查数据");
    }
    /**
     * 获取安全检查详细信息
     */
    @ApiOperation(value="获取安全检查详细信息", notes="获取安全检查详细信息")
    @PreAuthorize(hasPermi = "security:afSafetyInspection:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(afSafetyInspectionService.selectAfSafetyInspectionById(id));
    }

    /**
     * 新增安全检查
     */
    @ApiOperation(value="新增安全检查", notes="新增安全检查")
    @PreAuthorize(hasPermi = "security:afSafetyInspection:add")
    @Log(title = "安全检查", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AfSafetyInspection afSafetyInspection) {
        return toAjax(afSafetyInspectionService.insertAfSafetyInspection(afSafetyInspection));
    }

    /**
     * 修改安全检查
     */
    @ApiOperation(value="修改安全检查", notes="修改安全检查")
    @PreAuthorize(hasPermi = "security:afSafetyInspection:edit")
    @Log(title = "安全检查", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AfSafetyInspection afSafetyInspection) {
        return toAjax(afSafetyInspectionService.updateAfSafetyInspection(afSafetyInspection));
    }

    /**
     * 删除安全检查
     */
    @ApiOperation(value="删除安全检查", notes="删除安全检查")
    @ApiImplicitParam(name = "ids", value = "安全检查ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "security:afSafetyInspection:remove")
    @Log(title = "安全检查", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(afSafetyInspectionService.deleteAfSafetyInspectionByIds(ids));
    }
}
